Fix regression in QPointF::operator==
authorAllan Sandfeld Jensen <allan.jensen@qt.io>
Mon, 9 Jul 2018 13:30:49 +0000 (15:30 +0200)
committerLisandro Damián Nicanor Pérez Meyer <lisandro@debian.org>
Tue, 25 Sep 2018 21:26:54 +0000 (22:26 +0100)
Handle hard zero independently in each coordinate, otherwise hard zero
is never equal to anything but itself.

Task-number: QTBUG-69368
Change-Id: I8b1131472bb92efc706a04e0b067e2211a5ccb0c
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Gbp-Pq: Name fix_regresion_in_QPointF_operator_equals.patch

src/corelib/tools/qpoint.h
tests/auto/corelib/tools/qpointf/tst_qpointf.cpp

index ae46f0d39f604815095646197715b6e7f651b48b..d7323f770757012063f8031e46922eb5c3f9086a 100644 (file)
@@ -351,9 +351,8 @@ QT_WARNING_DISABLE_GCC("-Wfloat-equal")
 
 Q_DECL_CONSTEXPR inline bool operator==(const QPointF &p1, const QPointF &p2)
 {
-    return ((!p1.xp && !p1.yp) || (!p2.xp && !p2.yp))
-         ? (qFuzzyIsNull(p1.xp - p2.xp) && qFuzzyIsNull(p1.yp - p2.yp))
-         : (qFuzzyCompare(p1.xp, p2.xp) && qFuzzyCompare(p1.yp, p2.yp));
+    return ((!p1.xp || !p2.xp) ? qFuzzyIsNull(p1.xp - p2.xp) : qFuzzyCompare(p1.xp, p2.xp))
+        && ((!p1.yp || !p2.yp) ? qFuzzyIsNull(p1.yp - p2.yp) : qFuzzyCompare(p1.yp, p2.yp));
 }
 
 Q_DECL_CONSTEXPR inline bool operator!=(const QPointF &p1, const QPointF &p2)
index 579991a91277bb43195975254b828e16077f88ac..d4ccdf7ba601cf38e16fcd802012aa9ed97d01c9 100644 (file)
@@ -450,6 +450,9 @@ void tst_QPointF::compare()
     p3 -= QPointF(0.1, 0.1);
 
     QVERIFY(p3 == QPointF());
+
+    // Test we can compare one dimension with hard zero
+    QVERIFY(QPointF(1.9543e-14, -32.0) == QPointF(0.0, -32.0));
 }
 
 QTEST_MAIN(tst_QPointF)